package com.yao_shop.controller;

import com.yao_shop.service.Impl.token_serviceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/*
* 初衷.
*
* 注销登录
* */
@RestController
public class CencelloginController {
        @Autowired
        token_serviceImpl token_service;
@ResponseBody
@GetMapping(value = "/cencel.do")
@ApiOperation(value = "注销已经登录的用户",notes = "删除所有session完成注销")
public String cenecl(@RequestParam Map map, HttpServletRequest request){
        System.out.println(request.getSession().getAttribute("session_name")+"=注销");
        request.getSession().invalidate();
        return "success";
        }
        @ResponseBody
        @GetMapping(value = "/logout.do")
        public String logout(@RequestParam Map map, HttpServletRequest request){
                try {
                        String token = request.getHeader("token");
                        token_service.logout(token);
                }catch (Exception e){
                        System.out.println(e.getMessage());
                        return "fail";
                }
                return "success";
        }
}
